package org.shoukaiseki.inittable.utils

import org.shoukaiseki.inittable.utils.TableColumnInfoBuilder

/**
 *  常用字段 陀峰方式
 * <br>
 * @author shoukaiseki
 * ブログ http://www.shoukaiseki.top/<br>
 * E-メール jiang28555@Gmail.com<br>
 * @date 2021-10-17 17:48:41<br>
 */
object SksColumnCamelCaseCommon {

    @JvmStatic
    @JvmOverloads
    fun uniqueId(columnName: String,comment:String="ID"): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column("    ${columnName} bigint(20) unsigned auto_increment comment '${comment}' ")
            .primaryKey()
    }

    /**
     * 组织
     */
    @JvmStatic
    @JvmOverloads
    fun orgId(columnName: String="org_id",comment:String="组织"): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column(" ${columnName}  bigint(20) unsigned   null comment '$comment',")
    }

    /**
     * 站点
     */
    @JvmStatic
    @JvmOverloads
    fun siteId(columnName: String="site_id",comment:String="地点"): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column(" ${columnName}  bigint(20) unsigned   null comment '$comment',")
    }

    /**
     * 关联其它表的主键
     */
    @JvmStatic
    @JvmOverloads
    fun relationshipId(columnName: String,comment:String, defaultValue:Any?=null,notNull:Boolean=false): TableColumnInfoBuilder {
        var nullStr:String="null"
        if(notNull){
            nullStr="not null"
        }
        if (defaultValue==null) {
            return TableColumnInfoBuilder.column(" ${columnName}  bigint(20) unsigned            ${nullStr} comment '$comment',")
        }
        return TableColumnInfoBuilder.column(" ${columnName}  bigint(20) unsigned  default '${defaultValue}'    ${nullStr} comment '$comment',")
    }


    /**
     * 关联其它表的主键集合,逗号分割
     */
    @JvmStatic
    @JvmOverloads
    fun relationshipIdStr(columnName: String,comment:String,varLength:Int=512): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column("    ${columnName} varchar($varLength) default '' not null comment '${comment}' ")
    }


    /**
     * 工单数量
     */
    @JvmStatic
    fun proQuantity(columnName: String, comment:String): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column("    ${columnName}  decimal(20, 0)  default 0 not null comment '${comment}' ")
    }


    /**
     * 库存出入库(生产领料/采购入库)数量
     */
    @JvmStatic
    fun itemQuantity(columnName: String, comment:String): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column("    ${columnName}  decimal(20, 0)  default 0 not null comment '${comment}' ")
    }


//    /**
//     * 产品/原材料单价
//     */
//    @JvmStatic
//    fun itemUnitCost(columnName: String,comment:String): TableColumnInfoBuilder {
//        return TableColumnInfoBuilder.column("    ${columnName}  decimal(20, 2)  default 0 not null comment '${comment}' ")
//    }


    /**
     * 产品/原材料行价格
     */
    @JvmStatic
    fun itemLineCost(columnName: String, comment:String): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column("    ${columnName}  decimal(20, 2)  default 0 not null comment '${comment}' ")
    }


    /**
     * 工单计算工资单价
     */
    @JvmStatic
    fun proUnitCost(columnName: String,comment:String): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column("    ${columnName}  decimal(20, 6)   null comment '${comment}' ")
    }


    /**
     * 工单计算工资金额
     */
    @JvmStatic
    fun proLineCost(columnName: String,comment:String): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column("    ${columnName}  decimal(20, 6)   null comment '${comment}' ")
    }

    @JvmStatic
    @JvmOverloads
    fun sort(columnName: String="sort"): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column(" ${columnName}       int(12)             default '0'               not null comment '排序'")
    }

    @JvmStatic
    @JvmOverloads
    fun validFlag(comment:String="生效标识",defaultValue:String="1"): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column(" valid_flag       int(12)             default '$defaultValue'               not null comment '${comment}'")
            .description("1:未生效,0:生效" )

    }


    @JvmStatic
    @JvmOverloads
    fun workStatus(comment:String="工作状态"): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column(" work_status       int(12)             default '0'               not null comment '${comment}'")
            .description("0: 草稿,1:完成")
    }

    @JvmStatic
    @JvmOverloads
    fun status(comment:String="状态"): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column(" status       int(12)             default '0'               not null comment '${comment}'")
            .description("0:正常,1:禁用" +
                    "0:正常,1:归档")
    }


    @JvmStatic
    fun deptId(): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column(" dept_id            bigint(20) unsigned   null comment '部门',")
            .description("测试部门录入的数据全为测试数据,只做业务逻辑测试,不计入统计数据")
    }

    @JvmStatic
    fun createUserId(): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column(" create_user_id      bigint(20)  unsigned  null comment '创建人员',")
    }

    @JvmStatic
    fun createTime(): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column(" create_time    datetime            default current_timestamp not null comment '创建时间',")
    }

    @JvmStatic
    fun updateUserId(): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column(" update_user_id      bigint(20)  unsigned  null comment '更新人员',")
    }

    @JvmStatic
    @JvmOverloads
    fun updateTime(comment:String="更新时间"): TableColumnInfoBuilder {
//        return TableColumnInfoBuilder.column(" updateTime    datetime            default current_timestamp not null on update current_timestamp comment '$comment',")
        return TableColumnInfoBuilder.column(" update_time    datetime            null comment '$comment',")
    }

    /**
     * 只对虚拟删除时有效
     */
    @JvmStatic
    @JvmOverloads
    fun deleteTime(comment:String="删除时间"): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column(" delete_time    datetime            null  comment '$comment',")
    }

    @JvmStatic
    fun delFlag(): TableColumnInfoBuilder? {
        //过滤时搜索值为99代表显示所有
        return TableColumnInfoBuilder.column(" del_flag       char(1)             default '0'               not null comment '删除标志'")
            .description("（0代表存在 1代表删除 2缓存）")
    }


    @JvmStatic
    fun rowstamp(): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column("    rowstamp             bigint(20)          default '0'               not null comment '行标记',")
            .description(",每次更新该标志+1,保证库存的一致性")
    }

    /**
     * 库房/位置
     */
    @JvmStatic
    @JvmOverloads
    fun location(columnName: String="location", comment:String="库房", defaultValue:String="defaultLocation"): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column("  ${columnName} varchar(64)     default '${defaultValue}'     not null comment '${comment}',")
            .description("[defaultLocation:默认库房]")
    }

    /**
     * 库位/位置
     */
    @JvmStatic
    @JvmOverloads
    fun container(columnName: String="container", comment:String="库位", defaultValue:String="defaultContainer"): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column("  ${columnName} varchar(64)     default '${defaultValue}'     not null comment '${comment}',")
            .description("[defaultContainer:默认库位]")
    }

    @JvmStatic
    @JvmOverloads
    fun intColumnUnsigned(columnName:String, comment:String, defaultValue:Any?=0L): TableColumnInfoBuilder{
        if (defaultValue==null) {
            return TableColumnInfoBuilder.column(" ${columnName}  int(12) unsigned            null comment '$comment',")
        }
        return TableColumnInfoBuilder.column(" ${columnName}  int(12) unsigned  default '${defaultValue}'          not null comment '$comment',")
    }

    @JvmStatic
    @JvmOverloads
    fun intColumn(columnName:String, comment:String, defaultValue:Any?=0L): TableColumnInfoBuilder{
        if (defaultValue==null) {
            return TableColumnInfoBuilder.column(" ${columnName}  int(12)             null comment '$comment',")
        }
        return TableColumnInfoBuilder.column(" ${columnName}  int(12)  default '${defaultValue}'          not null comment '$comment',")
    }


    //日期时间类型
    @JvmStatic
//    @JvmOverloads
    fun datetimeColumn(columnName:String, comment:String): TableColumnInfoBuilder{
        return TableColumnInfoBuilder.column(" ${columnName}  datetime   null comment '$comment',")
    }

    //日期类型
    @JvmStatic
//    @JvmOverloads
    fun dateColumn(columnName:String, comment:String): TableColumnInfoBuilder{
        return TableColumnInfoBuilder.column(" ${columnName}  date   null comment '$comment',")
    }



    //物资图号
    @JvmStatic
    @JvmOverloads
    fun itemNum(columnName:String="item_num", comment:String="图号"): TableColumnInfoBuilder{
        return TableColumnInfoBuilder.column(" ${columnName}  varchar(64)  default ''          not null comment '$comment',")
    }

    //物资名称
    @JvmStatic
    @JvmOverloads
    fun itemName(columnName:String="item_name", comment:String="名称"): TableColumnInfoBuilder{
        return TableColumnInfoBuilder.column(" ${columnName}  varchar(128)  default ''          not null comment '$comment',")
    }


    //字符类型
    @JvmStatic
    @JvmOverloads
    fun varColumn(columnName:String, comment:String,varLength:Int=128,notNull:Boolean=false): TableColumnInfoBuilder{
        if(notNull){
            return TableColumnInfoBuilder.column(" ${columnName}  varchar($varLength)  default ''          not null comment '$comment',")
        }
        return TableColumnInfoBuilder.column(" ${columnName}  varchar($varLength)  default ''          null comment '$comment',")
    }



//    //需要物资需求标识
//    @JvmStatic
//    fun requestFlag(): TableColumnInfoBuilder{
//        return TableColumnInfoBuilder.column("    request_flag  tinyint(8) default '0' not null comment '需要物资需求标识',")
//            .description(AutumnDictUtils.getDictInfo(InventoryRequestFlag::class.java))
//    }
//
//    //提供物资需求标识
//    @JvmStatic
//    fun responseFlag(): TableColumnInfoBuilder{
//        return TableColumnInfoBuilder.column("    response_flag tinyint(8) default '0' not null comment '提供物资需求标识',")
//            .description(AutumnDictUtils.getDictInfo(InventoryResponseFlag::class.java))
//    }

    @JvmStatic
    @JvmOverloads
    fun gold(columnName: String,comment:String="积分",defaultValue:Any?=0L,notNull:Boolean=true): TableColumnInfoBuilder {
        var defaultTmp=""
        if(defaultValue!=null){
            defaultTmp=" default '${defaultValue}'"
        }
        if(notNull){
            return TableColumnInfoBuilder.column(" ${columnName}  bigint(20)  ${defaultTmp}          not null comment '$comment',")
        }
        return TableColumnInfoBuilder.column(" ${columnName}  bigint(20)  ${defaultTmp}          null comment '$comment',")
    }

    /**
     * 礼品数量
     */
    @JvmStatic
    fun goldMallQuantity(columnName: String, comment:String): TableColumnInfoBuilder {
        return TableColumnInfoBuilder.column("    ${columnName}  bigint(20)  default 0 not null comment '${comment}' ")
    }

    //字符类型
    @JvmStatic
    @JvmOverloads
    fun urlColumn(columnName:String, comment:String,varLength:Int=256,notNull:Boolean=false): TableColumnInfoBuilder{
        if(notNull){
            return TableColumnInfoBuilder.column(" ${columnName}  varchar($varLength)  default ''          not null comment '$comment',")
        }
        return TableColumnInfoBuilder.column(" ${columnName}  varchar($varLength)  default ''          null comment '$comment',")
    }


    /**
     * 产品价格
     * 结算都以unitCost价格为基准
     */
    @JvmStatic
    @JvmOverloads
    fun itemUnitCost(columnName: String, comment:String, defaultValue:Any?=0L, notNull:Boolean=false): TableColumnInfoBuilder {
        var defaultTmp=""
        if(defaultValue!=null){
            defaultTmp=" default '${defaultValue}'"
        }
        if(notNull){
            return TableColumnInfoBuilder.column("    ${columnName}  decimal(20, 2)  ${defaultTmp} not null comment '${comment}' ")
        }
        return TableColumnInfoBuilder.column("    ${columnName}  decimal(20, 2)  ${defaultTmp}  null comment '${comment}' ")
    }

    /**
     * 订单数量
     */
    @JvmStatic
    @JvmOverloads
    fun shopOrderQuantity(columnName: String,comment:String,defaultValue:Any?=0L): TableColumnInfoBuilder {
        var defaultTmp=""
        if(defaultValue!=null){
            defaultTmp=" default '${defaultValue}'"
        }
//        return TableColumnInfoBuilder.column("    ${columnName}  decimal(20, 0)  ${defaultTmp} not null comment '${comment}' ")
        return TableColumnInfoBuilder.column("    ${columnName}  int(12)  ${defaultTmp} not null comment '${comment}' ")
    }


}
